package com.lanou3g.dllo.baidumusic.musiclibrary.recommend.singersdetail;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.lanou3g.dllo.baidumusic.R;
import com.lanou3g.dllo.baidumusic.tools.MyRvOnClickListener;
import com.lanou3g.dllo.baidumusic.tools.SingleVolley;

import java.util.List;

/**
 * Created by dllo on 16/6/28.
 */
public class SingerDetailAdapter extends BaseAdapter{
    private SingerDetailBean singerDetailBean;
    private List<SingerDetailBean.SonglistBean> list;
    private Context context;
    private MyRvOnClickListener myRvOnClickListener;

    public void setMyRvOnClickListener(MyRvOnClickListener myRvOnClickListener) {
        this.myRvOnClickListener = myRvOnClickListener;
    }

    public void setSingerDetailBean(SingerDetailBean singerDetailBean) {
        this.singerDetailBean = singerDetailBean;
        list = singerDetailBean.getSonglist();
        notifyDataSetChanged();
    }

    public SingerDetailAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list == null ? null : list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_singerdetail,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        // 获得歌手姓名
        holder.singerDetailSongsnameTv.setText(list.get(position).getTitle());
        // 获得专辑名
        holder.singerDetailAlbumTv.setText("《" + list.get(position).getAlbum_title()+ "》");

        holder.singerDetailMoreBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                myRvOnClickListener.onClick(position);
            }
        });

        return convertView;
    }

    class ViewHolder{
        TextView singerDetailSongsnameTv,singerDetailAlbumTv;
        ImageView singerDetailMoreBtn;

        public ViewHolder(View view) {
            singerDetailSongsnameTv = (TextView) view.findViewById(R.id.singerdetail_songsname_tv);
            singerDetailAlbumTv = (TextView) view.findViewById(R.id.singerdetail_album_tv);
            singerDetailMoreBtn = (ImageView) view.findViewById(R.id.singerdetail_more_btn);

        }
    }
}
